package cn.yuemouren.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: Timi
 * @Description: 349. 两个数组的交集
 * @Date: 2020/8/4 8:58
 */
public class Test_349 {

    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<>();
        Set<Integer> res = new HashSet<>();
        for (int num : nums2)
            set.add(num);

        for (int num : nums1){
            if(set.contains(num))
                res.add(num);
        }
        int[] resArr = new int[res.size()];
        int i = 0;
        for (Integer re : res)
            resArr[i++] = re;
        return resArr;
    }
}
